package com.tancire.web.controller.net;

import com.tancire.common.annotation.Log;
import com.tancire.common.core.controller.BaseController;
import com.tancire.common.core.domain.AjaxResult;
import com.tancire.common.core.page.TableDataInfo;
import com.tancire.common.enums.BusinessType;
import com.tancire.common.utils.poi.ExcelUtil;
import com.tancire.net.domain.PurseInfo;
import com.tancire.net.service.IPurseInfoService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 会员钱包Controller
 *
 * @author chenchao
 * @date 2023-11-20
 */
@RestController
@RequestMapping("/net/purseInfo")
public class PurseInfoController extends BaseController {
    @Resource
    private IPurseInfoService purseInfoService;

    /**
     * 查询会员钱包列表
     */
    @PreAuthorize("@ss.hasPermi('net:purseInfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(PurseInfo purseInfo) {
        startPage();
        List<PurseInfo> list = purseInfoService.selectPurseInfoList(purseInfo);
        return getDataTable(list);
    }

    /**
     * 导出会员钱包列表
     */
    @PreAuthorize("@ss.hasPermi('net:purseInfo:export')")
    @Log(title = "会员钱包", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PurseInfo purseInfo) {
        List<PurseInfo> list = purseInfoService.selectPurseInfoList(purseInfo);
        ExcelUtil<PurseInfo> util = new ExcelUtil<PurseInfo>(PurseInfo.class);
        util.exportExcel(response, list, "会员钱包数据");
    }

    /**
     * 获取会员钱包详细信息
     */
    @PreAuthorize("@ss.hasPermi('net:purseInfo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(purseInfoService.selectPurseInfoById(id));
    }

    /**
     * 新增会员钱包
     */
    @PreAuthorize("@ss.hasPermi('net:purseInfo:add')")
    @Log(title = "会员钱包", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PurseInfo purseInfo) {
        return toAjax(purseInfoService.insertPurseInfo(purseInfo));
    }

    /**
     * 修改会员钱包
     */
    @PreAuthorize("@ss.hasPermi('net:purseInfo:edit')")
    @Log(title = "会员钱包", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PurseInfo purseInfo) {
        return toAjax(purseInfoService.updatePurseInfo(purseInfo));
    }

    /**
     * 删除会员钱包
     */
    @PreAuthorize("@ss.hasPermi('net:purseInfo:remove')")
    @Log(title = "会员钱包", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(purseInfoService.deletePurseInfoByIds(ids));
    }
}
